package com.elepro.shoppingmall.controller.comment;


import com.elepro.shoppingmall.entity.comments.Comment;
import com.elepro.shoppingmall.service.comment.CommentServiceIm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/comment")
@CrossOrigin
public class CommentController {
    @Autowired
    private CommentServiceIm commentServiceIm;

    @GetMapping("/list")
    public List<Comment> getCommentList(@RequestParam("goodsId") Long goodsId){
        return commentServiceIm.selectCommentListByGoodsId(goodsId);
    }

    @PostMapping("/create")
    public Integer insertComment(Comment comment,@RequestParam(value = "file",required = false) MultipartFile file){

        if (file !=null){
            comment = commentServiceIm.setCommentPictureUrl(comment,file);
        }
        return commentServiceIm.insertComment(comment);
    }

    @DeleteMapping("/delete")
    public Integer deleteComment(@RequestParam("id") Long id){
        return commentServiceIm.deleteComment(id);
    }
}
